package org.example;

public class Test1 {
    //leetcode  27 移除元素 https://leetcode.cn/problems/remove-element/description/

    /**
     * 经典的双指针问题
     * @param nums
     * @param val
     * @return
     */
    public int removeElement(int[] nums, int val) {
        int n = nums.length;
        int slow = -1, fast = 0, ret = n;
        while (fast < n) {
            if (nums[fast] != val) {
                nums[++slow] = nums[fast];
            }else {
                ret--;
            }
            fast++;
        }
        return ret;
    }
}
